<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveSupport::CoreExtensions::Hash::Keys</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveSupport::CoreExtensions::Hash::Keys</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/activesupport/lib/active_support/core_ext/hash/keys_rb.html">
                vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000622">assert_valid_keys</a>&nbsp;&nbsp;
      <a href="#M000616">stringify_keys</a>&nbsp;&nbsp;
      <a href="#M000617">stringify_keys!</a>&nbsp;&nbsp;
      <a href="#M000618">symbolize_keys</a>&nbsp;&nbsp;
      <a href="#M000619">symbolize_keys!</a>&nbsp;&nbsp;
      <a href="#M000620">to_options</a>&nbsp;&nbsp;
      <a href="#M000621">to_options!</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000622" class="method-detail">
        <a name="M000622"></a>

        <div class="method-heading">
          <a href="#M000622" class="method-signature">
          <span class="method-name">assert_valid_keys</span><span class="method-args">(*valid_keys)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Validate all keys in a hash match *valid keys, raising ArgumentError on a
mismatch. Note that keys are NOT treated indifferently, meaning if you use
strings for keys but assert symbol as keys, this will fail. examples:
</p>
<pre>
  { :name =&gt; &quot;Rob&quot;, :years =&gt; &quot;28&quot; }.assert_valid_keys(:name, :age) # =&gt; raises &quot;ArgumentError: Unknown key(s): years&quot;
  { :name =&gt; &quot;Rob&quot;, :age =&gt; &quot;28&quot; }.assert_valid_keys(&quot;name&quot;, &quot;age&quot;) # =&gt; raises &quot;ArgumentError: Unknown key(s): years, name&quot;
  { :name =&gt; &quot;Rob&quot;, :age =&gt; &quot;28&quot; }.assert_valid_keys(:name, :age) # =&gt; passes, raises nothing
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000622-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000622-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 47</span>
47:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_valid_keys</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">valid_keys</span>)
48:           <span class="ruby-identifier">unknown_keys</span> = <span class="ruby-identifier">keys</span> <span class="ruby-operator">-</span> [<span class="ruby-identifier">valid_keys</span>].<span class="ruby-identifier">flatten</span>
49:           <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Unknown key(s): #{unknown_keys.join(&quot;, &quot;)}&quot;</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">unknown_keys</span>.<span class="ruby-identifier">empty?</span>
50:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000616" class="method-detail">
        <a name="M000616"></a>

        <div class="method-heading">
          <a href="#M000616" class="method-signature">
          <span class="method-name">stringify_keys</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return a new hash with all keys converted to strings.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000616-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000616-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 6</span>
 6:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stringify_keys</span>
 7:           <span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">options</span>, (<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)<span class="ruby-operator">|</span>
 8:             <span class="ruby-identifier">options</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">value</span>
 9:             <span class="ruby-identifier">options</span>
10:           <span class="ruby-keyword kw">end</span>
11:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000617" class="method-detail">
        <a name="M000617"></a>

        <div class="method-heading">
          <a href="#M000617" class="method-signature">
          <span class="method-name">stringify_keys!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Destructively convert all keys to strings.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000617-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000617-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 14</span>
14:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stringify_keys!</span>
15:           <span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
16:             <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;String&quot;</span> <span class="ruby-comment cmt"># weird hack to make the tests run when string_ext_test.rb is also running</span>
17:               <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-keyword kw">self</span>[<span class="ruby-identifier">key</span>]
18:               <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
19:             <span class="ruby-keyword kw">end</span>
20:           <span class="ruby-keyword kw">end</span>
21:           <span class="ruby-keyword kw">self</span>
22:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000618" class="method-detail">
        <a name="M000618"></a>

        <div class="method-heading">
          <a href="#M000618" class="method-signature">
          <span class="method-name">symbolize_keys</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return a new hash with all keys converted to symbols.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000618-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000618-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 25</span>
25:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">symbolize_keys</span>
26:           <span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">options</span>, (<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)<span class="ruby-operator">|</span>
27:             <span class="ruby-identifier">options</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_sym</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
28:             <span class="ruby-identifier">options</span>
29:           <span class="ruby-keyword kw">end</span>
30:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000619" class="method-detail">
        <a name="M000619"></a>

        <div class="method-heading">
          <a href="#M000619" class="method-signature">
          <span class="method-name">symbolize_keys!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Destructively convert all keys to symbols.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000619-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000619-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 33</span>
33:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">symbolize_keys!</span>
34:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">symbolize_keys</span>)
35:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000620" class="method-detail">
        <a name="M000620"></a>

        <div class="method-heading">
          <span class="method-name">to_options</span><span class="method-args">()</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Keys.html#M000618">symbolize_keys</a>
</p>
        </div>
      </div>

      <div id="method-M000621" class="method-detail">
        <a name="M000621"></a>

        <div class="method-heading">
          <span class="method-name">to_options!</span><span class="method-args">()</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Keys.html#M000618">symbolize_keys</a>!
</p>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>